﻿using CPPEI.Coolzon.UI.Script;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI
{ 
    public partial class PartFrame
    {
        /// <summary>
        /// 是否显示放大镜
        /// </summary>
        public bool XIsShowMagnify
        {
            get
            {
                return (bool)GetValue(XIsShowMagnifyProperty);
            }
            set
            {
                SetValue(XIsShowMagnifyProperty, value);
            }
        }

        /// <summary>
        /// 放大镜的左位置
        /// </summary>
        public double XMagnifyLeft
        {
            get
            {
                return (double)GetValue(XMagnifyLeftProperty);
            }
            set
            {
                SetValue(XMagnifyLeftProperty, value);
            }
        }

        /// <summary>
        /// 放大镜的右位置
        /// </summary>
        public double XMagnifyTop
        {
            get
            {
                return (double)GetValue(XMagnifyTopProperty);
            }
            set
            {
                SetValue(XMagnifyTopProperty, value);
            }
        }

        /// <summary>
        /// 放大镜的放大源
        /// </summary>
        public Brush XMagnifySource
        {
            get
            {
                return (Brush)GetValue(XMagnifySourceProperty);
            }
            set
            {
                SetValue(XMagnifySourceProperty, value);
            }
        }


        public static readonly DependencyProperty XIsShowMagnifyProperty = DependencyProperty.Register("XIsShowMagnify",
            typeof(bool), typeof(PartFrame),
            new PropertyMetadata(false));
        public static readonly DependencyProperty XMagnifyLeftProperty = DependencyProperty.Register("XMagnifyLeft",
            typeof(double), typeof(PartFrame),
            new PropertyMetadata(default(double), XMagnifyLeftPropertyChangedCallback));
        public static readonly DependencyProperty XMagnifyTopProperty = DependencyProperty.Register("XMagnifyTop",
            typeof(double), typeof(PartFrame),
            new PropertyMetadata(default(double), XMagnifyTopPropertyChangedCallback));
        public static readonly DependencyProperty XMagnifySourceProperty = DependencyProperty.Register("XMagnifySource",
            typeof(Brush), typeof(PartFrame));


        private static void XMagnifyTopPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PartFrame part = d as PartFrame;
            if (part.XMagnifySource != null)
            {
                Rect viewBox = (part.XMagnifySource as VisualBrush).Viewbox;
                viewBox.X = part.XMagnifyLeft + 300 - (viewBox.Width / 2.0d);// -xoffset;
                viewBox.Y = part.XMagnifyTop + 300 - (viewBox.Height / 2.0d);// -yoffset;
                (part.XMagnifySource as VisualBrush).Viewbox = viewBox;
            }
        }

        private static void XMagnifyLeftPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PartFrame part = d as PartFrame;
            if (part.XMagnifySource != null)
            {
                Rect viewBox = (part.XMagnifySource as VisualBrush).Viewbox;
                viewBox.X = part.XMagnifyLeft + 300 - (viewBox.Width / 2.0d);// -xoffset;
                viewBox.Y = part.XMagnifyTop + 300 - (viewBox.Height / 2.0d);// -yoffset;
                (part.XMagnifySource as VisualBrush).Viewbox = viewBox;
            }
        }

        /// <summary>
        /// 是否显示激光笔
        /// </summary>
        public bool XIsShowLaserPointer
        {
            get
            {
                return (bool)GetValue(XIsShowLaserPointerProperty);
            }
            set
            {
                SetValue(XIsShowLaserPointerProperty, value);
            }
        }

        /// <summary>
        /// 激光笔的左位置
        /// </summary>
        public double XLaserPointerLeft
        {
            get
            {
                return (double)GetValue(XLaserPointerLeftProperty);
            }
            set
            {
                SetValue(XLaserPointerLeftProperty, value);
            }
        }

        /// <summary>
        /// 激光笔的右位置
        /// </summary>
        public double XLaserPointerTop
        {
            get
            {
                return (double)GetValue(XLaserPointerTopProperty);
            }
            set
            {
                SetValue(XLaserPointerTopProperty, value);
            }
        }

        /// <summary>
        /// 激光笔的颜色
        /// </summary>
        public Brush XLaserPointerColor
        {
            get
            {
                return (Brush)GetValue(XLaserPointerColorProperty);
            }
            set
            {
                SetValue(XLaserPointerColorProperty, value);
            }
        }
        public static readonly DependencyProperty XIsShowLaserPointerProperty = DependencyProperty.Register("XIsShowLaserPointer",
            typeof(bool), typeof(PartFrame),
            new PropertyMetadata(false));
        public static readonly DependencyProperty XLaserPointerLeftProperty = DependencyProperty.Register("XLaserPointerLeft",
            typeof(double), typeof(PartFrame));
        public static readonly DependencyProperty XLaserPointerTopProperty = DependencyProperty.Register("XLaserPointerTop",
            typeof(double), typeof(PartFrame));
        public static readonly DependencyProperty XLaserPointerColorProperty = DependencyProperty.Register("XLaserPointerColor",
            typeof(Brush), typeof(PartFrame));
    }
}
